{- InterQuery.inc.orc -- Orc program InterQuery.inc
 - 
 - $Id$
 - 
 - Created by akattepu on 07-Aug-2012 17:05:47
 -}

def bestQoS(comparer, publisher) = head(sortBy(comparer, publisher))
val curTime = Rclock()
type Millisecond = Number
def Millisecond() = signal
type Second = Number
def Second() = signal 

-- Types and Definitions for Inter Query Time
type InterQueryTime = Number
def class InterQueryTime(unit)=
  def QoS(String) :: Number
  def QoS(sitex) =
    val s = {. r = Ref(0), c = Channel() .}
    signal >>(sitex,
    s.r? >p> (s.c.put(curTime.time()-p) | s.r:=(curTime.time())) >> Dictionary() >sitex> sitex.InterQueryTime := s)
    >> (Ift(unit = Millisecond) >> s.r? | Ift(unit = Second) >> s.r?/1000)
   
  def QoSCompare(Number,Number) :: Number
  def QoSCompare(it1,it2) = it1 >= it2
  
  def QoSCompete(Number,Number) :: Number
  def QoSCompete(it1,it2) = bestQoS(QoSCompare,[it1,it2])
  stop 